home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0060_ASM File Deletion.pas < prev    next >
Pascal/Delphi Source File  |  1995-03-03  |  892b  |  42 lines

  1. {
  2. > In my program I create some temporary files, but I like to delete them
  3. > before my program is finished.
  4.  
  5. Here, the assembly code:
  6. }
  7.  
  8. Function DeleteFile(FileName : string) : integer; assembler;
  9. { Deletes an external file.
  10.     Returns: 0 if successful, non-zero DOS error code otherwise. }
  11. Asm
  12.   push ds
  13.   lds si,FileName
  14.   inc byte ptr [si]
  15.   mov bl,byte ptr [si]
  16.   xor bh,bh
  17.   mov dx,si
  18.   inc dx
  19.   mov byte ptr [si+bx],0
  20.   mov ah,41h
  21.   int 21h
  22.   jc  @error
  23.   xor ax,ax
  24. @error:
  25.   dec byte ptr [si]
  26.   pop ds
  27. End; { DeleteFile }
  28.  
  29. var
  30.   Result : integer;
  31.   Path : string;
  32.  
  33. Begin
  34.   Path := 'C:\AUTOEXEC.BAK';
  35.   Write('Attempting to delete ', Path, '... ');
  36.   Result := DeleteFile(Path);
  37.   if Result = 0 then
  38.     WriteLn(#13, Path, ' successfully deleted.  ')
  39.   else
  40.     WriteLn(#13'Unable to delete ', Path, '. DOS error ', Result, ' occured.')
  41. End.
  42.